package com.songlanyun.modules.singlegoods.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.songlanyun.modules.rabbitmq.MqConstant;
import com.songlanyun.modules.rabbitmq.service.SendMsgService;
import com.songlanyun.modules.singlegoods.entity.UnderStockRecordEntity;
import com.songlanyun.modules.singlegoods.service.SendUnderStockRecordMsgService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("sendUnderStockRecordMsgService")
public class SendUnderStockRecordMsgImpl implements SendUnderStockRecordMsgService {


    @Resource
    private SendMsgService sendMsgService;

    /**
     * 库存不足记录
     *
     * @param underStockRecordEntity
     */
    @Override
    public void send(UnderStockRecordEntity underStockRecordEntity) {
        sendMsgService.sendCommon(MqConstant.UnderStockRecordConstant.UNDER_STOCK_RECORD_EXCHANGE, MqConstant.UnderStockRecordConstant.UNDER_STOCK_RECORD_ROUTING
                , JSONObject.toJSONString(underStockRecordEntity));
    }

    /**
     * 更新库存不足的单品记录状态
     * @param singleGoodsId
     */
    @Override
    public void sendInStock(Long singleGoodsId) {
        sendMsgService.sendCommon(MqConstant.UnderStockStatusConstant.UNDER_STOCK_STATUS_EXCHANGE, MqConstant.UnderStockStatusConstant.UNDER_STOCK_STATUS_ROUTING
                , String.valueOf(singleGoodsId));
    }


}

